﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"

namespace gnuf {
    class Info;
    class QtSearchBox;

    class GNUF_BASE_EXPORT SearchDataModel
    {
    public:
        SearchDataModel() {}
        virtual ~SearchDataModel() {}

    public:
        virtual const std::list<std::wstring> search(const std::wstring&) { return{}; }
    };

    class GNUF_BASE_EXPORT SearchBox final : public ItemWith<QtSearchBox>
    {
        CANNOT_COPY_OR_ASSIGN(SearchBox)
    public:
        static const EItemType Type;
        explicit SearchBox(Item* );
        virtual ~SearchBox();
        
    public:
        inline bool isAutoSearch() const { return m_bAutoSearch; }
        void setAutoSearch(bool bAuto) { m_bAutoSearch = bAuto; }

        inline bool hasHistoryList() const { return m_hasHistoryList; }
        inline unsigned int historyLimit() const { return m_historyLimit; }
        void setHasHistoryList(bool hasHistoryList, unsigned int historyLimit = 10);

        inline bool hasDeleteAction() const { return m_hasDeleteAction; }
        void setHasDeleteAction(bool hasDeleteAction) { m_hasDeleteAction = hasDeleteAction; }

        inline const std::wstring& placeholder() const { return m_placeholder; }
        void setPlaceholder(const std::wstring& placeholder) { m_placeholder = GBMP_TR(placeholder); }

        std::wstring iconPath();
        void setIcon(const std::wstring& iconPath);

        std::wstring searchIconPath();
        void setSearchIcon(const std::wstring& iconPath);

        std::wstring deleteIconPath();
        void setDeleteIcon(const std::wstring& deleteIconPath);

        void attachModelData(SearchDataModel* modelData) { m_modelData = modelData; }
        inline SearchDataModel* modelData() { return m_modelData; }

        void search(const std::wstring&);
        void clear();

    protected:
        // Inherits from Item...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onPostAppearanceSettingChanged() override;
    private:
        bool m_bAutoSearch;
        bool m_hasHistoryList;
        bool m_hasDeleteAction;
        unsigned int m_historyLimit;
        std::wstring m_placeholder;
        gcmp::OwnerPtr<Info> m_iconInfo;
        gcmp::OwnerPtr<Info> m_searchHandle;
        gcmp::OwnerPtr<Info> m_deleteHandle;
        SearchDataModel* m_modelData;
    };
}
